/*
 * @Script: t6.c
 * @Author: ystlong
 * @Email: ystlong@163.com
 * @Create At: yyyy-03-dd 21:25:28
 * @Last Modified By: ystlong
 * @Last Modified At: yyyy-03-dd 21:25:28
 * @Description: This is description.
 */
#include <stdio.h>
#include <stdlib.h>

int *merge(int *data1, int *data2, int length1, int length2)
{
    int *result = malloc(sizeof(int) *(length1+length2));
    int *merge_p = result;
    int i=0, j=0;
    for(;i<length1; i++){
        while(j < length2 && data2[j] <= data1[i]){
            *merge_p++ = data2[j++];
        }
        *merge_p++ = data1[i];
    }
    for(;j<length2;j++)
        *merge_p++ = data2[j];
    return result;
}

int main()
{
    int d1[5] = {1, 3, 4, 4, 5};
    int d2[3] = {1, 3, 3};
    // int *r = merge(d1, d2, 5, 3);
    int *r = merge(d2, d1, 3, 5);
    for(int i=0; i< 8; i++){
        printf("%d ", r[i]);
    }
    printf("\n");
    return 0;
}